﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MenuManage.aspx.cs" Inherits="ProjectStudy.MenuManage.MenuModify" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <style type="text/css">
table.altrowstable {
	font-family: verdana,arial,sans-serif;
	font-size:14px;
	color:#333333;
	border-width: 1px;
	border-color: #a9c6c9;
	border-collapse: collapse;
}
table.altrowstable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #a9c6c9;
}
table.altrowstable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #a9c6c9;
}
.oddrowcolor{
	background-color:#d4e3e5;
}
.evenrowcolor{
	background-color:#c3dde0;
}
</style>

    <style type="text/css">
        .wordhid
        {
            display:block;
            width:100px;
            text-overflow:ellipsis;
            }
        input[type="reset"]::-moz-focus-inner, 
        input[type="button"]::-moz-focus-inner, 
        input[type="submit"]::-moz-focus-inner, 
        input[type="file"] > input[type="button"]::-moz-focus-inner{ 
        border:none;padding:0; 
    </style>
    <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {

            $.ajax({
                type: "post",
                url: "/Ajax/Menu_Manage.ashx",
                data: { "action": "GetGroup", "requirement": "all" },
                dataType: "json",
                success: function (data) {
                    $.each(data, function (index, item) {
                        $("#sel1").append('<option id="' + 'op' + (index + 1) + '">' + item.GroupName + '</option>')
                    });

                    var groupsel = GetQueryString("groupsel");
                    if (groupsel != null & groupsel != '') {
                        
                        $("#sel1").val(groupsel);
                        searchData();
                    }
                    else {
                        groupsel = 'all';
                        $("#sel1").val(groupsel);
                    }
                    
                }
            });



            $("#btnSearch").click(function () {
                searchData();
            });
            $("#btnDel").click(function () {
                del();
            });

            $("#btnEdit").click(function () {
                FnEdit();
            });

            $("#btnAdd").click(function () {
                location.href = "/MenuManage/MenuAdd.aspx";
            });
        });

        function del() {
            var chks = $("input[name='chkItem']");
            var arrMenuIds = [];
            var arrTr = [];
            var arrPageIds = [];
            for (var i = 0; i < chks.length; i++) {
                if (chks[i].checked) {
                    arrTr.push($(chks[i]).parent().parent().attr('id'));
                    arrMenuIds.push($(chks[i]).parent().next().html());
                    if ($(chks[i]).parent().next().next().next().next().next().html().length > 0) {
                        arrPageIds.push($(chks[i]).parent().next().next().next().next().next().html());
                    }
                }
            }
            if (arrMenuIds.length <= 0) {
                alert("请最少选择一个");
            }
            else {
                if (confirm("确认删除?") == true) {
                    $.ajax({
                        type: "Post",
                        url: "../Ajax/Menu_Manage.ashx",
                        data: { "action": "MenuDel", "menuId": JSON.stringify(arrMenuIds), "pageid": JSON.stringify(arrPageIds) },
                        dataType: "json",
                        success: function (data) {
                            if (data["status"] == "success") {
                                for (var i = 0; i < arrTr.length; i++) {
                                    $("#" + arrTr[i]).remove();
                                }
                            }
                        },
                        error: function (err) {
                            alert(err);
                        }
                    });
                }
            }
        }

        function FnEdit() {
            var chks = $("input[name='chkItem']");
            var menuId = "";
            var fatherId = "";
            var menuName = "";
            var menuURL = "";
            var group = "";
            var pageid = "";
            for (var i = 0; i < chks.length; i++) {
                if (chks[i].checked) {
                    menuId = $(chks[i]).parent().next().html();
                    fatherId = $(chks[i]).parent().next().next().html();
                    menuName = $(chks[i]).parent().next().next().next().html();
                    menuURL = $(chks[i]).parent().next().next().next().next().html();
                    group = $(chks[i]).parent().next().next().next().next().next().next().html();
                    pageid = $(chks[i]).parent().next().next().next().next().next().html();
                    break;
                }
            }
            if (menuId != "") {
                location.href = encodeURI(encodeURI("/MenuManage/MenuModify.aspx?menuId=" + menuId + "&fatherId=" + fatherId + "&menuName=" + menuName + "&menuURL=" + menuURL + "&group=" + group + "&groupsel=" + $("#sel1").val()+"&pageId="+pageid));
            }
            else {
                alert("请选择一行数据");
            }
        }

        function searchData() {
            $("#tb1").html("");
            var requirement = $("#sel1").find("option:selected").text();

            $.ajax({
                type: "post",
                url: "/Ajax/Menu_Manage.ashx",
                data: { "action": "MenuSearch", "requirement": requirement },
                dataType: "json",
                success: function (data) {
                    //var json = eval("(" + data + ")");
                    if (data != null && data != '') {
                        $("#tb1").append('<tr id="' + 'tr' + 0 + '"></tr>');
                        $("#tr0").append('<td>' + '<input type="checkbox" id="cb0"/>' + '</td>');
                        $("#tr0").append('<td style="display:none;">' + '菜单ID' + '</td>');
                        $("#tr0").append('<td style="display:none;">' + '菜单父ID' + '</td>');
                        $("#tr0").append('<td>' + '菜单名称' + '</td>');
                        $("#tr0").append('<td>' + '页面URL' + '</td>');
                        $("#tr0").append('<td style="display:none;">' + '页面ID' + '</td>');
                        $("#tr0").append('<td>' + '菜单所属用户组' + '</td>');
                        $("#tr0").append('<td>' + '创建人' + '</td>');
                        $("#tr0").append('<td>' + '创建时间' + '</td>');
                        $("#tr0").append('<td>' + '修改人' + '</td>');
                        $("#tr0").append('<td>' + '修改时间' + '</td>');

                        $("#cb0").click(function () {
                            $("input[name='chkItem']").attr("checked", $("#cb0").attr("checked"));
                        });

                        $.each(data, function (index, item) {
                            var pageid = item.pageId == null ? '' : item.pageId;
                            var modifyBy = item.modifyBy == null ? '' : item.modifyBy;
                            var modifyT = item.modifyTime == null ? '' : item.modifyTime.replace('T', ' ');
                            $("#tb1").append('<tr id="' + 'tr' + (index + 1) + '"></tr>');
                            $("#" + "tr" + (index + 1)).append('<td>' + '<input type="checkbox" id="' + 'cb' + (index + 1) + '" name="chkItem" />' + '</td>');
                            $("#" + "tr" + (index + 1)).append('<td style="display:none;">' + item.menuId + '</td>');
                            $("#" + "tr" + (index + 1)).append('<td style="display:none;">' + item.fatherId + '</td>');
                            $("#" + "tr" + (index + 1)).append('<td>' + item.menuName + '</td>');
                            $("#" + "tr" + (index + 1)).append('<td>' + item.url + '</td>');
                            $("#" + "tr" + (index + 1)).append('<td style="display:none;">' + pageid + '</td>');
                            $("#" + "tr" + (index + 1)).append('<td>' + item.userGroup + '</td>');
                            $("#" + "tr" + (index + 1)).append('<td>' + item.createBy + '</td>');
                            $("#" + "tr" + (index + 1)).append('<td>' + item.createTime.replace('T', ' ') + '</td>');
                            $("#" + "tr" + (index + 1)).append('<td>' + modifyBy + '</td>');
                            $("#" + "tr" + (index + 1)).append('<td>' + modifyT + '</td>');
                        });
                    }
                    else {
                        alert("没有数据");
                    }
                }
            });
        }

        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return decodeURI(unescape(r[2])); return null;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
   <div>
    <label style=" height:30px; line-height:30px; font-size:16px;">用户组</label>
    <select id="sel1" style=" height:30px; line-height:30px; font-size:16px;">
      <option id="op0" selected="selected">all</option>
    </select>
    <input  type="button" id="btnSearch" value="搜索" style=" height:30px; line-height:30px; font-size:16px; text-align:center;"/>
    <br />
    <br />
    <input  type="button" value="新增" id="btnAdd" style=" height:30px; line-height:30px; font-size:16px;"/>
    <input  type="button" value="编辑" id="btnEdit" style=" height:30px; line-height:30px; font-size:16px;"/>
    <input  type="button" value="删除" id="btnDel" style=" height:30px; line-height:30px; font-size:16px;"/>
    <br />
    <br />
    <table id="tb1" border="1" cellpadding="0" cellspacing="0" class="altrowstable">
     
    </table>
    </div>
    </form>
</body>
</html>
